package com.jic.product.impl;

import java.lang.Long;
import java.util.List;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.product.entity.Warehouse;
import com.jic.product.mapper.WarehouseMapper;
import com.jic.product.manage.request.WarehouseRequest;
import com.jic.product.manage.response.WarehouseResponse;
import com.jic.product.service.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 仓库表
 * @author :
 * @email :
 * @since : 2020-01-16 04:47:43
 * @version : v1.0.0
 */
@Service
public class WarehouseServiceImpl implements WarehouseService {

    @Autowired
    private WarehouseMapper warehouseMapper;

    @Override
    public long insert(Warehouse warehouse) {
        long flag = warehouseMapper.insert(warehouse);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return warehouseMapper.delete(id);
    }

    @Override
    public long update(Warehouse warehouse) {
        return warehouseMapper.update(warehouse);
    }

    @Override
    public Warehouse queryByPrimaryKey(Long id){
        return warehouseMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<Warehouse> query(Warehouse warehouse){
        return warehouseMapper.query(warehouse);
    }

    @Override
    public PageResult<WarehouseResponse> queryPage(WarehouseRequest warehouse, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<WarehouseResponse> list = warehouseMapper.queryPage(startIndex, pageQuery.getLimit(), warehouse);
        long count = warehouseMapper.queryPageCount(warehouse);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}
